package de.hsos.samcomm.common;

import de.hsos.samcomm.common.i18n.I18nFacade;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

/**
 *
 * @author Dennis
 */
public class MessageHandler {

    public static void addExceptionFacesMessage(Exception ex) {
        addContextFacesMessage(FacesMessage.SEVERITY_FATAL, ex.getLocalizedMessage(), "");
    }

    public static void addContextFacesMessage(Severity severity, String resourceKey, String infoKey) {
        I18nFacade i18n = I18nFacade.getInstance();
        String msg = i18n.getString(resourceKey);
        String info = i18n.getString(infoKey);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, msg, info));
    }
}
